package P1线性结构;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Random;

public class TestArrayList {
    public static void main(String[] args) {
        /*
        ArrayList<Integer> list = new ArrayList<>();
        System.out.println(list);
        for (int i = 1; i <= 8; i++) {
            list.add(i);
        }
        System.out.println(list);
        list.add(0,9);
        System.out.println(list);
        list.add(5,10);
        System.out.println(list);
        list.add(11);
        System.out.println(list);
        System.out.println(list.remove(0));
        System.out.println(list);
        for (int i = 1; i <= 8; i++) {
            System.out.println(list.remove(0));
            System.out.println(list);
        }
        */
        ArrayList<Integer> listA = new ArrayList<>();
        Random random = new Random();
        for (int i = 1; i <= 12; i++) {
            listA.add(random.nextInt(100));
        }
        System.out.println(listA);
        System.out.println(listA.sublist(3,9));
        listA.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1; //降序
//                return o1 - o2; //升序
            }
        });
        System.out.println(listA);
        for (Integer num : listA) {
            System.out.println(num);
        }
        Iterator<Integer> it = listA.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        ArrayList<Integer> listB = new ArrayList<>();
        ArrayList<Integer> listC = new ArrayList<>();
        for (int i = 1; i <= 6; i++) {
            listB.add(i);
        }
        System.out.println(listB);
        for (int i = 1; i <= 15; i++) {
            listC.add(i);
        }
        System.out.println(listC);
        for (int i = 1; i <= 9; i++) {
            listC.remove(6);
        }
        System.out.println(listC);
        System.out.println(listB.equals(listC));
        System.out.println(listB.equals(listA));
        System.out.println(listB.equals(new String()));
    }
}